
"""
simple test of resolver.call_Url
"""

from whiff import resolver
from whiff import whiffenv

def __wsgi__(env, start_response):
    # extract the user, date and title parameters from the URL path remainder
    path_remainder = env[whiffenv.PATH_REMAINDER]
    operation = "show" # default operation
    if len(path_remainder)==5:
        (user, year, month, day, title) = path_remainder
    elif len(path_remainder)==6:
        (user, year, month, day, title, operation) = path_remainder
    else:
        raise ValueError, "I don't know how to translate path remainder of this length "+repr(path_remainder)
    # modify the cgi dictionary to include the user, date and title parameters
    env = resolver.process_cgi(env, parse_cgi=True)
    cgi_dict = env[whiffenv.CGI_DICTIONARY].copy()
    cgi_dict["user"] = [user]
    cgi_dict["year"] = [year]
    cgi_dict["month"] = [month]
    cgi_dict["day"] = [day]
    cgi_dict["title"] = [title]
    env[whiffenv.CGI_DICTIONARY] = cgi_dict
    # delegate the response to blog_root/OPERATION
    url = "blog_root/" + operation
    return resolver.callUrl(url, env, start_response)

